package com.cyf.mq.consumer.simple;

import com.cyf.mq.common.constant.MQConstant;
import com.cyf.mq.common.pojo.HeroDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author chenyifan
 * @create 2025-02-17 13:50
 */
@Component
@RocketMQMessageListener(
        topic = MQConstant.MESSAGE_TOPIC_King,
        consumerGroup = MQConstant.MESSAGE_CONSUMER_GROUP_A,
        // 默认：CONCURRENTLY：并发消费模式 多线程
        //      ORDERLY：顺序消费模式 单线程
        consumeMode = ConsumeMode.ORDERLY,
        // 消息重试次数，在并发模式下，-1 表示 16; 在 orderly 模式下，-1 表示 Integer.MAX_VALUE。
        maxReconsumeTimes = 3,
        // tag过滤模式
        selectorType = SelectorType.TAG,
        // 过滤标签
        selectorExpression = MQConstant.MESSAGE_TAG_SHOOTER,
        // 开启消费者方的轨迹
        enableMsgTrace = true
)
@Slf4j
public class MessageConsumer implements RocketMQListener<HeroDTO> {
    @Override
    public void onMessage(HeroDTO body) {
        log.info("MessageConsumer 接收到消息: {}", body);
    }
}